package com.acme.concurrent.factorization;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Gregory Sobko
 */
public class SieveOfEratosthenes {

    public static Set<Integer> getPrimeNumbers(int limit){
        Set<Integer> result = new HashSet<Integer>();
        assert limit > 2;
        // fill with all ints
        for (int i = 2; i <= limit; i++) {
            result.add(i);
        }
        //now let's filter!
        for (int i = 2; i <= 1 + (limit/2); i++) {
            if(result.contains(i)){
                for (int j = 2; i*j <= limit; j++) {
                    result.remove(i*j);
                }
            }

        }
        return result;
    }

}
